﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace JsonRpc
{
    public class JsonRpcRequest
    {
        public string id { get; set; }
        public string jsonrpc { get; set; }
        public string method { get; set; }
        public List<object> parameters;
    }

    public class JsonRpcResponse
    {
        public string jsonrpc { get; set; }
        public object result { get; set; }
        public JsonRpcError error { get; set; }
        public string id { get; set; }

        public JsonRpcResponse()
        {
            jsonrpc = "2.0";
            result = null;
            error = null;
            id = null;
        }

        public JsonRpcResponse(Exception ex)
        {
            error = new JsonRpcError(ex);
        }
    }

    public class JsonRpcError
    {
        public int code { get; set; }
        public string message { get; set; }
        public object data { get; set; }
        
        public JsonRpcError()
            : this(0, null, null)
        {
        }

        public JsonRpcError(int code, string message)
            : this(code, message, null)
        {
        }

        public JsonRpcError(string message)
            : this(-1, message, null)
        {
        }

        public JsonRpcError(int code, string message, object data)
        {
            this.code = code;
            this.message = message;
            this.data = data;
        }

        public JsonRpcError(Exception ex)
        {
            this.message = ex.Message;
            this.data = ex.StackTrace;
        }

    }



}